<?php
/**
 * 商品类
 * Create by PhpStorm
 * User: lijia
 * Data: 2020/8/21
 * Time: 10:22
 */

namespace app\api\controller;


use app\api\business\GoodsBus;

class Goods extends Common
{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 所有商品
     * @return \think\response\Json
     */
    public function getAll()
    {
        try{
            $list = (new GoodsBus())->getAll();
            return resJson(200,'ok',$list);
        }catch (\Exception $e){
            return resJson(0,$e->getMessage());
        }
    }


    /**
     * 按照分类获取商品
     * @return \think\response\Json
     */
    public function index(){
        try{
            $list = (new GoodsBus())->getList();
            return resJson(200,'ok',$list);
        }catch (\Exception $e){
            return resJson(0,$e->getMessage());
        }
    }


    /**
     * 推荐商品
     */
    public function recommend()
    {
        $id = input('param.id',0,'intval');
        if (!$id) return resJson(0,'参数错误');
        $list = (new GoodsBus())->recommend($id);
        return resJson(200,'ok',$list);
    }

    /**
     * 商品详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function info(){
        $id = input('param.id',0,'intval');
        if (!$id) return resJson(0,'参数错误');
        $info = (new GoodsBus())->info($id);
        return resJson(200,'ok',$info);
    }



}